import api from '../../http/api'


export default {
    namespaced: true,
    state: {
        // personalMsg: [],
        workingData: [],
        femaleData: [],
        manData: [],
        serveType: []
    },
    mutations: {
        setOnWorking(state, newData) {
            state.workingData = newData.list
        },
        setFemaleData(state, newData) {
            state.femaleData = newData.list.filter(item => item.technician_gender == '女')
        },
        setManData(state, newData) {
            state.manData = newData.list.filter(item => item.technician_gender == '男')
        },
        setServeType(state, newData) {
            state.serveType = newData.object
            // console.log(state.setServeType);
        },
        searchFemale(state, newData) {

            state.femaleData = [...new Set(newData.filter(item => item.technician_gender == '女'))]
        },
        searchMan(state, newData) {
            state.manData = [...new Set(newData.filter(item => item.technician_gender == '男'))]
        }
    },
    actions: {
        //获取技师信息
        async findAll(context) {
            // console.log(context);
            const data = await api.technician.findAll()
            console.log(data.data.data.list);
            if (data.status) {
                context.commit('setOnWorking', data.data.data)
                context.commit('setFemaleData', data.data.data)
                context.commit('setManData', data.data.data)
            }
        },
        //查询技师
        async serviceTechnicianState(context, msg) {
            console.log(msg);
            const data = await api.technician.serviceTechnicianState(msg)
            console.log('搜索结果', data.data.data);
            if (data.status == 200) {
                context.commit('searchFemale', data.data.data)
                context.commit('searchMan', data.data.data)
            }
        },
        //查询所有服务项目
        async selectAll(context) {
            const data = await api.technician.selectAll()
            // console.log('服务项目', data);
            // console.log(data.data.object);
            if (data.status == 200) {
                context.commit('setServeType', data.data)
            }
        }
    }

}